<?php

namespace app\test\controller;

use think\Controller;
use think\Db;
use think\facade\View;
use think\Request;

class Three extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function create()
    {
        //
        if(\request()->isPost()){
            $arr=\request()->post();
            $file=\request()->file('img');
            $info=$file->move('./uploads');
            $arr['img']='/uploads/'.$info->getSaveName();
          $user=new \app\test\model\Three();
          $res=$user->table('three')->insert($arr);
          if ($res){
              $this->success('添加成功','show');
          }else{
              $this->error('添加失败','create');
          }
        }
        return View::fetch('create');
    }

    public function show(Request $request)
    {
        $user=new \app\test\model\Three();
        $data=$user->table('three')->select();
        return View::fetch('show',['data'=>$data]);
    }
    public function delete($id)
    {
        $id=\request()->param('id');
        $user=new \app\test\model\Three();
        $res=$user->table('three')->where('id',$id)->delete();
        if ($res){
            $this->success('删除成功','show');
        }else{
            $this->error('删除失败','show');
        }
    }
}
